package com.meatball.game.controller

import com.meatball.game.data.*
import com.meatball.game.service.AiGameService
import io.swagger.v3.oas.annotations.Hidden
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.Parameters
import io.swagger.v3.oas.annotations.enums.ParameterIn
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

/**
 * TODO 游戏基础信息控制层
 *
 * @author 张翔宇
 * @since 2024年3月7日
 */
@Tag(name = "AI游戏")
@RestController
@RequestMapping("/game")
class AiGameController (private val aiGameService: AiGameService) {
    /**
     * TODO 生成随机用户
     *
     * @return
     */
    @Operation(summary = "生成随机用户")
    @GetMapping("/generator-random-user")
    fun generatorRandomUser() : RandomUser {
        return aiGameService.randomUser()
    }

    /**
     * TODO 投票
     *
     * @param roomId
     * @param data
     * @return
     */
    @Operation(summary = "投票")
    @Parameters(
            Parameter(name = "roomId", description = "房间编号", `in` = ParameterIn.PATH, required = true, example = "512d63af0df24cd0be7e66a387da914c")
    )
    @PostMapping("/vote/{roomId}")
    fun castingVote(@PathVariable roomId: String, @RequestBody data: CastingVote) : CastingVoteResult {
        return aiGameService.castingVote(roomId, data)
    }

    /**
     * TODO 获取房间内用户列表
     *
     * @param roomId
     * @return
     */
    @Operation(summary = "获取房间内用户列表")
    @Parameters(
            Parameter(name = "roomId", description = "房间编号", `in` = ParameterIn.PATH, required = true, example = "512d63af0df24cd0be7e66a387da914c")
    )
    @GetMapping("/get-user/{roomId}")
    fun getUsers(@PathVariable roomId: String) : List<RoomUser>? {
        return aiGameService.getUsers(roomId)
    }

    /**
     * TODO 获取投票结果
     *
     * @param roomId
     * @return
     */
    @Operation(summary = "获取投票结果")
    @Parameters(
            Parameter(name = "roomId", description = "房间编号", `in` = ParameterIn.PATH, required = true, example = "512d63af0df24cd0be7e66a387da914c")
    )
    @GetMapping("/get-vote-result/{roomId}")
    fun getVoteResult(@PathVariable roomId: String) : GetVoteResult {
        return aiGameService.getVoteResult(roomId)
    }

    @Hidden
    @GetMapping("/test-redis")
    fun testRedis() {
        aiGameService.testRedis()
    }

    @Operation(summary = "上传文件")
    @PostMapping("/upload", headers = ["content-type=multipart/form-data"])
    fun handleFileUpload(@RequestPart("file") file: MultipartFile) {
        aiGameService.handleFileUpload(file)
    }
}